package com.ares.comparer.config;

public class Result<T> {
    private static final int SUCCESS_CODE = 1;
    private static final int FAIL_CODE = 0;

    private static final String SUCCESS_MSG = "操作成功";
    private static final String FAIL_MSG = "操作失败";

    private int code;
    private String msg;
    private T data;

    private Result(int code) {
        this.code = code;
    }

    private Result(int code, T data) {
        this.code = code;
        this.data = data;
    }

    private Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<T>(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<T>(SUCCESS_CODE, msg);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<T>(SUCCESS_CODE, msg, data);
    }

    public static <T> Result<T> fail() {
        return new Result<T>(FAIL_CODE, FAIL_MSG);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<T>(FAIL_CODE, msg);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return new Result<T>(code, msg);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<T>(FAIL_CODE, FAIL_MSG, data);
    }

    public static <T> Result<T> fail(String msg, T data) {
        return new Result<T>(FAIL_CODE, msg, data);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
